﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Rubik.Base;

namespace SimpleRubikSolution
{
    public class RubikSolution : ICubeSerializer
    {
        public string Serialize(byte[][,] data)
        {
            BinaryString binaryString = new BinaryString();
            for (int i = 0; i < 6; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    for (int k = 0; k < 3; k++)
                    {
                        byte color = data[i][j, k];
                        binaryString.Push(color, 3);
                    }
                }
            }
            return binaryString.Build();
        }

        public byte[][,] Deserialize(string serializedData)
        {
            BinaryString binaryString = new BinaryString(serializedData);
            byte[][,] data = new byte[6][,];
            for (int i = 0; i < 6; i++)
            {
                data[i] = new byte[3, 3];
                for (int j = 0; j < 3; j++)
                {
                    for (int k = 0; k < 3; k++)
                    {
                        int color = binaryString.PopBits(3);
                        data[i][j, k] = (byte) color;
                    }
                }
            }
            return data;
        }
    }
}
